<template>
  <a-modal :title="$t('批量修改')" :width="width" :visible="visible" :confirmLoading="confirmLoading" :okText="$t('保存')"
    :cancelText="$t('关闭')" @ok="handleOk" @cancel="handleCancel" v-drag>
    <a-spin :spinning="confirmLoading">
      <a-form class="batchForm">
        <a-form-item :label="$t('选择修改的属性')" :labelCol="{ span: 7 }" :wrapperCol="{ span: 15 }">
          <a-select v-model="dataForm.editState" allowClear
            :getPopupContainer="(triggerNode) => { return triggerNode.parentNode || document.body }">
            <!-- <a-select-option key="state">{{ $t('适用会员') }}</a-select-option> -->
            <a-select-option key="inputSpeed">{{ $t('投币速度') }}</a-select-option>
            <a-select-option key="inputWidth">{{ $t('投币脉宽') }}</a-select-option>
            <a-select-option key="inputPolarity">{{ $t('投币极性') }}</a-select-option>
            <a-select-option key="outputSpeed">{{ $t('退票速度') }}</a-select-option>
            <a-select-option key="outputWidth">{{ $t('退票脉宽') }}</a-select-option>
            <a-select-option key="outputPolarity">{{ $t('退票极性') }}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item v-if="dataForm.editState === 'inputSpeed'" :label="$t('修改属性为')" :labelCol="{ span: 7 }"
          :wrapperCol="{ span: 15 }">
          <j-dict-select-tag :placeholder="$t('请选择')" v-model="dataForm.inputSpeed" dictCode="bis_game.speed" />
        </a-form-item>
        <a-form-item v-if="dataForm.editState === 'inputWidth'" :label="$t('修改属性为')" :labelCol="{ span: 7 }"
          :wrapperCol="{ span: 15 }">
          <a-input v-model="dataForm.inputWidth"></a-input>
        </a-form-item>
        <a-form-item v-if="dataForm.editState === 'inputPolarity'" :label="$t('修改属性为')" :labelCol="{ span: 7 }"
          :wrapperCol="{ span: 15 }">
          <j-dict-select-tag :placeholder="$t('请选择')" v-model="dataForm.inputPolarity" dictCode="bis_game.polarity" />
        </a-form-item>
        <a-form-item v-if="dataForm.editState === 'outputSpeed'" :label="$t('修改属性为')" :labelCol="{ span: 7 }"
          :wrapperCol="{ span: 15 }">
          <j-dict-select-tag :placeholder="$t('请选择')" v-model="dataForm.outputSpeed" dictCode="bis_game.speed" />
        </a-form-item>
        <a-form-item v-if="dataForm.editState === 'outputWidth'" :label="$t('修改属性为')" :labelCol="{ span: 7 }"
          :wrapperCol="{ span: 15 }">
          <a-input v-model="dataForm.outputWidth"></a-input>
        </a-form-item>
        <a-form-item v-if="dataForm.editState === 'outputPolarity'" :label="$t('修改属性为')" :labelCol="{ span: 7 }"
          :wrapperCol="{ span: 15 }">
          <j-dict-select-tag :placeholder="$t('请选择')" v-model="dataForm.outputPolarity" dictCode="bis_game.polarity" />
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
import { putAction } from '@/api/manage'

export default {
  name: 'BatchEditGameModal',
  data() {
    return {
      title: this.$t('操作'),
      width: 800,
      visible: false,
      model: {},
      gameIdList: [],
      confirmLoading: false,
      reultList: [],
      dataForm: {
        editState: '',
        status: 'N',
      },
      dataForms: {},
      queryList: [],
      treeData: [],
      allChildKind: [],
    }
  },
  methods: {
    edit(datas) {
      this.gameIdList = datas
      this.dataForm = {
        editState: '',
      }
      this.dataForms = {}
      this.visible = true
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      let that = this
      that.queryList = []
      let url = '/game/bisGame/updateBatch'
      if (that.dataForm.editState == '') {
        that.$message.warn(that.$t('请选择需要修改的属性'))
        return
      } else {
        if (
          that.dataForm.editState != 'inputSpeed' &&
          that.dataForm.editState != 'inputWidth' &&
          that.dataForm.editState != 'inputPolarity' &&
          that.dataForm.editState != 'outputSpeed' &&
          that.dataForm.editState != 'outputWidth' &&
          that.dataForm.editState != 'outputPolarity'
        ) {
          that.$message.warn(that.$t('请选择修改属性'))
          return
        }
        if (that.dataForm.editState == 'inputSpeed') {
          if (that.dataForm.inputSpeed === undefined || that.dataForm.inputSpeed === '') {
            that.$message.warn(that.$t('投币速度不能为空'))
            return
          }
          that.dataForms.inputSpeed = that.dataForm.inputSpeed
        }
        if (that.dataForm.editState == 'inputWidth') {
          if (that.dataForm.inputWidth === undefined || that.dataForm.inputWidth === '') {
            that.$message.warn(that.$t('投币脉宽不能为空'))
            return
          }
          that.dataForms.inputWidth = that.dataForm.inputWidth
        }
        if (that.dataForm.editState == 'inputPolarity') {
          if (that.dataForm.inputPolarity === undefined || that.dataForm.inputPolarity === '') {
            that.$message.warn(that.$t('投币极性不能为空'))
            return
          }
          that.dataForms.inputPolarity = that.dataForm.inputPolarity
        }
        if (that.dataForm.editState == 'outputSpeed') {
          if (that.dataForm.outputSpeed === undefined || that.dataForm.outputSpeed === '') {
            that.$message.warn(that.$t('退币速度不能为空'))
            return
          }
          that.dataForms.outputSpeed = that.dataForm.outputSpeed
        }
        if (that.dataForm.editState == 'outputWidth') {
          if (that.dataForm.outputWidth === undefined || that.dataForm.outputWidth === '') {
            that.$message.warn(that.$t('退币脉宽不能为空'))
            return
          }
          that.dataForms.outputWidth = that.dataForm.outputWidth
        }
        if (that.dataForm.editState == 'outputPolarity') {
          if (that.dataForm.outputPolarity === undefined || that.dataForm.outputPolarity === '') {
            that.$message.warn(that.$t('退币极性不能为空'))
            return
          }
          that.dataForms.outputPolarity = that.dataForm.outputPolarity
        }
      }
      console.log(that.dataForms)
      that.gameIdList.forEach((item) => {
        let aa = {}
        aa = that.dataForms
        aa = Object.assign({}, that.dataForms)
        aa.id = item
        that.queryList.push(aa)
      })
      putAction(url, that.queryList).then((res) => {
        if (res.success) {
          that.$message.success(res.message)
          that.visible = false
          that.$emit('ok')
        } else {
          that.$message.warning(res.message)
        }
      })
    },
    handleCancel() {
      this.close()
    },
  },
}
</script>
<style>
.batchForm .ant-form-item-label {
  width: 30%;
}

.batchForm .ant-form-item-control-wrapper {
  width: 62.5%;
}
</style>